package com.aluka.nirvana.framework.security.handler;

import com.aluka.nirvana.framework.security.utils.ResponseUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义 Security 用户暂无权限处理类
 * @author gongli
 * @since 2019/4/10 13:40
 */
@Component
public class CustomAuthAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest,
                       HttpServletResponse httpServletResponse,
                       AccessDeniedException e) throws IOException, ServletException {
        ResponseUtils.writeResponse(httpServletResponse, HttpStatus.UNAUTHORIZED,"暂无权限访问此功能!");
    }
}
